﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using Nova.IdGenerator.Interface;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace Nova.IdGenerator.Test
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestGenerate()
        {
            int times = 100;
            //机器ID
            ushort workerID = 1;
            //1:飘移算法,2:经典算法
            short method = 1;
            //数据中心ID
            uint dataCenterID = 0;
            IdGeneratorOptions options = new IdGeneratorOptions(workerID)
            {
                DataCenterId = dataCenterID,
                Method = method
            };
            Generator.SetIdGenerator(options);
            List<long> IdList = new List<long>();
            for(int i = 0; i < times; i++)
            {
                var currentID = Generator.NextId();
                IdList.Add(currentID);
                Debug.WriteLine(currentID);
            }
            int IdCount = IdList.Count;
            int DistinctIDCount = IdList.Distinct().ToList().Count;
            Assert.AreEqual<int>(IdCount, DistinctIDCount);
        }
    }
}
